﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mime;
using System.Web;
using HRM.DAL.DAO;
using HRM.DAL.Gateway;

namespace HRM.BLL
{
    public class ApplicationManager
    {
        ApplicationGateway gateway=new ApplicationGateway();
        public bool SendApplication(Code code,LeaveApplication application)
        {
            EmployeeManager empManager=new EmployeeManager();
            int empId = empManager.GetEmployeeID(code);
            return gateway.SendApplication(empId, application);
        }
        public List<LeaveApplication> GetAllApplication()
        {
            return gateway.GetAllApplication();
        }

        public LeaveApplication ReadApplication(int applicationId)
        {
          //  EmployeeManager empManager = new EmployeeManager();
         //   int empId = empManager.GetEmployeeID();
            LeaveApplication application=new LeaveApplication();
            application = gateway.ReadApplication(applicationId);
            if(application.Employee.EmpCode.CodeName!="")
            {
                gateway.UpdateFlag(applicationId);
            }
            return application;
        }
        public int CountUnReadApplication()
        {
            return gateway.CountUnReadApplication();
        }
        public bool ApproveLeave(Code code,LeaveApplication application)
        {
            EmployeeManager empManager = new EmployeeManager();
            int empId = empManager.GetEmployeeID(code);
            gateway.ApproveLeave(application);
            LeaveStatusManager leaveStatusManager=new LeaveStatusManager();
            leaveStatusManager.UpdateEmployeeLeaveStatus(code, application);
            return true;
        }

        public bool DeleteApplication(int id)
        {
            return gateway.DeleteApplication(id);
        }
        public void RejectApplication(int applicationId, string status)
        {
            gateway.RejectApplication(applicationId, status); 
        }
        public List<LeaveApplication> GetApplicationStatus(Code code)
        {
            EmployeeManager empManager = new EmployeeManager();
            int empId = empManager.GetEmployeeID(code);
            return gateway.GetApplicationStatus(empId);
        } 
    }
}